package com.sh.common.page;

import java.util.List;

public class PageBean {

	private int totalPage; // 总页数
	private int currentPage; // 当前页数，最小为1
	private int pageSize; // 每页记录数
	private int totalCount; // 总记录数
	private List list; // 查询到的列表
	
	public PageBean() {
		super();
	}

	/**
	 * 设置总页数、当前页数、每页记录数、总记录数，在分页方法后这些值都属于正常范围
	 */
	public PageBean(int totalCount, int pageSize, int currentPage){
		// 总页数
		if(totalCount <=0){
			this.totalPage =  0;
		}else{
			this.totalPage = ((totalCount - 1) / pageSize) + 1;
		}
		// 当前页数
		if (currentPage == Integer.MAX_VALUE ) {
			this.currentPage = this.totalPage;
		}else if(currentPage == 1 && this.totalPage == 0){
			this.currentPage = currentPage;
		}else if(currentPage > this.totalPage){
			this.currentPage = this.totalPage;
		}else{
			this.currentPage = currentPage;
		}
		// 每页记录数
		this.pageSize = pageSize;
		// 总记录数
		this.totalCount = totalCount;
	}
	
	/**
	 * 获取任一页第一条数据的位置，从1开始包含1
	 */
	public int getStartOfPage(){
		return (this.currentPage-1)*this.pageSize+1;
	}
	
	/**
	 * 获取任一页第最后一条数据的位置，从1开始包含1
	 */
	public int getEndOfPage(){
		return this.currentPage*this.pageSize;
	}
	
	/**
	 * 是否有上一页
	 */
	 public boolean hasPreviousPage() {
		 return (this.currentPage > 1);
	 }
	 
	/**
	 * 是否有下一页
	 */
	 public boolean hasNextPage() {
		 return (this.currentPage < this.totalPage);
	 }
	 
	/**
	 * 是否有首页
	 */
	 public boolean hasFirstPage() {
		 return (this.currentPage > 1);
	 }
	 
	/**
	 * 是否有末页
	 */
	 public boolean hasLastPage() {
		 // 防止currentPage=0,totalPage=0
		 return (this.totalPage > 1 && this.currentPage < this.totalPage);
	 }
	 
	public int getTotalPage() {
		return totalPage;
	}
	
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}
	
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	public int getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public int getTotalCount() {
		return totalCount;
	}
	
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	public List getList() {
		return list;
	}
	
	public void setList(List list) {
		this.list = list;
	}

}
